package cn.wolfcode.wms.qo;

import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Calendar;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.Map;

@Setter
@Getter
public class SaleChartQueryObject extends QueryObject {
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date beginDate;
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date endDate;

    private Long clientId = -1L;
    private Long brandId = -1L;

    private String groupBy = "e.name";

    public static final Map<String, String> groupTypes = new LinkedHashMap<>();

    static {
        groupTypes.put("e.name", "销售人员");
        groupTypes.put("p.name", "货品名称");
        groupTypes.put("c.name", "客户");
        groupTypes.put("p.brand_name", "品牌");
        groupTypes.put("DATE_FORMAT(sa.vdate,\'%Y-%m\')", "销售日期(月)");
        groupTypes.put("DATE_FORMAT(sa.vdate,\'%Y-%m-%d\')", "销售日期(日)");
    }

    public void setEndDate(Date date) {
        if (date == null) {
            return;
        }
        Calendar caledar = Calendar.getInstance();
        caledar.setTime(date);
        caledar.set(Calendar.HOUR_OF_DAY, 23);
        caledar.set(Calendar.MINUTE, 59);
        caledar.set(Calendar.SECOND, 59);
        this.endDate = caledar.getTime();
    }
}
